<?php
include("config.php");
//提交验证码后

if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['code']) || empty($_POST['token']) ){
	echo json_res(true,'paramError','提交数据不全!');
	return;
}

//模拟登录
$snoopy = new Snoopy; 
$submit_url = $loginurl;
//定义POST内容
$submit_vars["__VIEWSTATE"]          = $_SESSION["__VIEWSTATE"];
$submit_vars["__VIEWSTATEGENERATOR"] = $_SESSION["__VIEWSTATEGENERATOR"];
$submit_vars['ctl00$txtusername']    = $_POST["username"];
$submit_vars['ctl00$txtpassword']    = $_POST["password"];
$submit_vars['ctl00$txtyzm']         = $_POST["code"];
$submit_vars['ctl00$ImageButton1.x'] = 46;
$submit_vars['ctl00$ImageButton1.y'] = 22;

//模拟HEADER
$snoopy->agent = $agent;
$snoopy->host = IP;
$snoopy->referer = $submit_url;
$snoopy->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];

$_SESSION["userID"] = $_POST["username"];
//提交
$snoopy->submit($submit_url,$submit_vars);

//超时返回
if ($snoopy->status != '200' || $snoopy->timed_out) {
	echo json_res(true,'systemTimeOut',"登录提交超时！");
	return;
}

$snoopy_results = $snoopy->results;

if(stripos($snoopy_results,"密码错误")){
	echo json_res(true,'paramError',"用户名或密码错误！");
	return;
}
if(stripos($snoopy_results,"你输入的验证码错误")){
	echo json_res(true,'paramError',"验证码错误！");
	return;
}
if(stripos($snoopy_results,"验证码失效")){
	echo json_res(true,'paramError',"验证码失效！");
	return;
}
if(stripos($snoopy_results,"不能登录本系统")){
	echo json_res(true,'paramError',"用户已被注销！");
	return;
}

if(!stripos($snoopy_results,"loging.aspx")){
	echo json_res(true,'paramError',"未知错误！");
	return;
}

//如果只验证登录信息，不进行登录后的其他操作
if(empty($login_do)){
	//noapi调用
	if(!empty($_POST['noapi'])){
		echo '登录成功!';
		return;
	}
	echo json_res(false,true,'登录成功!');
	return;
}
